﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using NHibernate;
using NHibernate.Context;
using Thaire.Investment.Repository;

namespace Thaire.Investment.Service
{
    public class Global : System.Web.HttpApplication
    {

   
        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            ManagedWebSessionContext.Bind( HttpContext.Current,SessionManager.SessionFactory.OpenSession());
        }

        protected void Application_EndRequest(object sender, EventArgs e)
        {
            ISession session = ManagedWebSessionContext.Unbind( HttpContext.Current, SessionManager.SessionFactory);
            if (session != null)
            {
                if (session.Transaction != null &&
                    session.Transaction.IsActive)
                {
                    session.Transaction.Rollback();
                }
              //  else
                   // session.Flush();
                session.Close();
                session.Dispose();
            }
        }

     
    }
}